package com.ldj.hibernate;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;

/**
 * Data access object (DAO) for domain model class TTest.
 * 
 * @see com.ldj.hibernate.TTest
 * @author MyEclipse Persistence Tools
 */

public class LoginDAO extends BaseHibernateDAO {
	public LoginDAO(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
		// TODO Auto-generated constructor stub
	}
	private static final Log log = LogFactory.getLog(TTestDAO.class);

//工作人员用户登陆
	public List findByNameAndPwd(String username,String password) {
		log.debug("finding by Username and Password");
		try {
			String queryString = "from PersionFile as p  where p.perFileDelOper='0' and p.perFileLoginName=? and p.perFileLoginPass=?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, username);
			queryObject.setParameter(1, password);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by Username and Password failed", re);
			throw re;
		}
	}
	
	
	
	//工作人员修改密码
	public PersionFile merge(PersionFile detachedInstance) {
		log.debug("merging PersionFile instance");
		try {
			PersionFile result = (PersionFile) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
//单位用户登陆
	public List unitFindByNameAndPwd(String username,String password) {
		log.debug("finding by Username and Password");
		try {
			String queryString = "from UnitUser as u where u.unitUserLoginName=? and u.unitUserPassword=?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, username);
			queryObject.setParameter(1, password);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by Username and Password failed", re);
			throw re;
		}
	}
	//单位用户修改密码
	public UnitUser unitMerge(UnitUser detachedInstance) {
		log.debug("merging UnitUser instance");
		try {
			UnitUser result = (UnitUser) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
	
}